package com.itheima.project.interceptor;

import com.itheima.project.constant.SuperConstant;
import com.itheima.project.utils.EmptyUtil;
import com.itheima.project.utils.SubjectContent;
import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
 * @ClassName FeignAuthRequestInterceptor.java
 * @Description feign请求授权拦截器
 */
public class FeignAuthRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {

        if (!EmptyUtil.isNullOrEmpty(SubjectContent.getUserToKen())){
            template.header(SuperConstant.USER_TOKEN, SubjectContent.getUserToKen());
        }

        if (!EmptyUtil.isNullOrEmpty(SubjectContent.getStore())){
            template.header(SuperConstant.STORE_TOKEN, SubjectContent.getStore());
        }
        // 多租户开关传递
        if (!EmptyUtil.isNullOrEmpty(SubjectContent.getTenantEnable())){
            template.header(SuperConstant.ENABLE_TENANT,String.valueOf(SubjectContent.getTenantEnable()) );
        }

    }
}
